from zope import schema
from zope.interface import Interface

from zope.app.container.constraints import contains

from itx.bookscatalog import bookscatalogMessageFactory as _

# Interfaces for the Basic content types

class IBook(Interface):
    """A book
    """

    title = schema.TextLine(title=_(u"Book title"),
                            required=True)
    
    isbn = schema.TextLine(title=_(u"ISBN number"),
                            description=_(u"ISBN unique number for the book"),
                            required=True)

    authors = schema.TextLine(title=_(u"Book author(s)"),
                        description=_(u"Lists of authors of the book"),
                        required=True)

    summary = schema.TextLine(title=_(u"Short summary"),
                            description=_(u"Short description of the book"),
                            required=True)

    teaser = schema.SourceText(title=_(u"Teaser"),
                            description=_(u"A teaser/description of the book"),
                            required=True)

    publisher = schema.TextLine(title=_(u"Publisher"),
                            description=_(u"Book's publisher"),
                            required=True)
    
    edition = schema.TextLine(title=_(u"Edition"),
                            description=_(u"Book's edition"))

    stock = schema.Int(title=_(u"Stock"),
                            description=_(u"Availability of this book"),
                            required=True)

class IBooksCatalog(Interface):
    """A book's catalog: a folder containing books
    """
    contains('itx.bookscatalog.interfaces.IBook',)

    title = schema.TextLine(title=_(u"Catalog's title"),
                            required=True)

    description = schema.TextLine(title=_(u"Short description"))

# Interfaces for some views and adapters

class IBooksCatalogView(Interface):
    """A view for the BooksCatalog
    """
    def title():
        """Title of the context catalog
        """
    def parent_url():
        """Parent url of the context object
        """
    def getBooksList():
        """retrive books from BooksCatalog adapter,
        filtered by request attributes
        """
    def hasModifyPermissions():
        """Has the actual member modify permissions
        """

# This is an adapter for the BooksCatalog 
# content type to hold the main methods
# and separate factory stuff from main functionality

class ICatalogManager(Interface):
    """A manager for a BooksCatalog content type
    """
    books = schema.List(title=_(u"Books"),
                        description=_(u"Lists books in catalog"),
                        required=True)
    def getBooks(query, max):
        """retrive list of books from the books catalog,
        quieried by quiery. If no books, return None.
        """
    def delBooks(books_list):
        """Delete books with id's given
        by books_list.
        """
